
#include "auto_feed.h"

// 不能用的pin 
// 6 7 8 9 10 11(chip flash)
// 18 19 21(RTC)
// 22 23 (OLED) 
// 24 29 30

user_device devices[CC_CONFIG_DEVICE_MAX_NUM] = {
    // { CC_NULL, CC_DEVICE_TYPE_SCALE, 1, { SCALE_PIN1, SCALE_PIN2 } },
    {CC_NULL, CC_DEVICE_TYPE_LED, 1, {LED_PIN}, .num_data = {LED_NUM}},
    {CC_NULL, CC_DEVICE_TYPE_SERVO, 1, {SERVO_PIN}},
    {CC_NULL, CC_DEVICE_TYPE_PHOTOSENSITIVE, 1, {PHOTOSENSITIVE_PIN}},
    {CC_NULL, CC_DEVICE_TYPE_INFRARED, 1, {INFRARED_PIN}},
    {CC_NULL, CC_DEVICE_TYPE_THERMOMETER, 1, {THERMOMETER_PIN}},
};

float setting_weight = 50;





// void shell_feed_timer_del_cb(char *topic, char *msg, int length, int topic_len)
// {
//   int type;
//   int arg_cnt = cc_shell_parse_args(msg, "%d", &type);
//   if (type >= 0 && type <= 2)
//   {
//     if (time_works[type].is_used)
//     {
//       cc_work_cancel(&time_works[type].work);
//     }
//     else
//     {
//       time_works[type].is_used = 0;
//     }
//   }
//   cc_msg_resp(CC_MSG_MQTT_NODE, "del success\r\n", 0, 0);
//   return;
// }

// CC_TOPIC_SUBSRIBE_ALIAS(shell_feed_timer_del_cb, "cc_feed_time_del");
// #endif

// // 串口模拟mqtt测试部分
// void shell_auto_feed_mqtt_cb(char *msg, int send_node)
// {
//   cc_port_t mqtt_port = cc_port_init(CC_PORT_AUTO_FEED_MQTT, "feed_mqtt", 10, 50);
//   cc_port_set_state(mqtt_port, CC_PORT_STATE_CONN);
//   cc_mnode_t node = CC_NULL;
//   if (strcmp(msg, "servo_open") == 0 || strcmp(msg, "servo_close") == 0)
//   {
//     node = cc_port_get_msg_node(mqtt_port, 1000);
//     sprintf((char *)node->mem, msg);
//     cc_port_publish(mqtt_port, "servo_ctrl", node);
//   }
// }
// CC_COMMAND_SHELL_ALIAS(shell_auto_feed_mqtt_cb, "auto_feed", "analog mqtt");

// void shell_feed_timer_cb(char *msg, int send_node)
// {
//   cc_port_t mqtt_port = cc_port_init(CC_PORT_AUTO_FEED_MQTT, "feed_mqtt", 10, 50);
//   cc_port_set_state(mqtt_port, CC_PORT_STATE_CONN);
//   int type = 0;
//   int hour = 0, min = 0, sec = 0;
//   int arg_cnt = cc_shell_parse_args(msg, "%d %d %d %d", &type, &hour, &min, &sec);
//   cc_log("set time:%d %d %d\r\n", hour, min, sec);

//   int now_tick = ((cc_hour) * 3600 * 100 + (cc_min) * 60 * 1000 + (cc_sec) * 1000);
//   int delay_tick = ((hour) * 3600 * 100 + (min) * 60 * 1000 + (sec) * 1000);
//   int delay_time = 0;
//   if (now_tick > delay_tick)
//   {
//     delay_time = 24 * 60 * 60 * 10000 + (delay_tick - now_tick);
//   }
//   else
//   {
//     delay_time = delay_tick - now_tick;
//   }
//   int test_time = delay_time / 1000;
//   cc_log("delay time:%d next:%d %d %d \r\n", delay_time, test_time / 3600 % 24, test_time / 60 % 60, test_time % 60);
//   if (type >= 0 && type <= 2)
//   {
//     if (time_works[type].is_used)
//     {
//       cc_work_cancel(&time_works[type].work);
//     }
//     else
//     {
//       time_works[type].is_used = 1;
//     }
//     cc_work_submit(&time_works[type].work, delay_time);
//   }
//   return;
// }

// CC_COMMAND_SHELL_ALIAS(shell_feed_timer_cb, "feed_timer_set", "analog mqtt");

// void shell_feed_timer_del_cb(char *msg, int send_node)
// {
//   int type;
//   int arg_cnt = cc_shell_parse_args(msg, "%d", &type);
//   if (type >= 0 && type <= 2)
//   {
//     if (time_works[type].is_used)
//     {
//       cc_work_cancel(&time_works[type].work);
//     }
//     else
//     {
//       time_works[type].is_used = 0;
//     }
//   }
//   return;
// }

// CC_COMMAND_SHELL_ALIAS(shell_feed_timer_del_cb, "feed_timer_del", "analog mqtt");
